﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PKURG.CostSplit.Business.QueryBase;

namespace PKURG.CostSplit.Business
{
    public class Project
    {
        public static List<dynamic> GetERPProjectList()
        {
            return ExecuteQuery.GetList(
                new QueryBase.QueryInfo()
                {
                    ProcName = "usp_GetEProjectList"
                });
        }
        private static List<dynamic> GetProjectList(string name)
        {
            return ExecuteQuery.GetList(
            new QueryBase.QueryInfo()
            {
                ProcName = "usp_n_GetUserAccessProjectList",
                Params = { name }
            });
        }

        public static List<dynamic> GetProjectStageList(string projectStageId)
        {
            return ExecuteQuery.GetList(
                new QueryBase.QueryInfo()
                {
                    ProcName = "usp_n_GetCanUseProjectStageList",
                    Params = { projectStageId }
                });
        }

        public static List<dynamic> GetProjectAllData()
        {
            List<dynamic> allData = new List<dynamic>();
            List<dynamic> projectList = GetERPProjectList();
            foreach (dynamic item in projectList)
            {
                List<dynamic> stageList = GetProjectStageList(item.Id);
                allData.Add(new
                {
                    Id = item.Id,
                    PName = item.ProjectName,
                    StageList = stageList
                }.ToDynamic());
            }
            return allData;
        }

        public static List<dynamic> GetProjectAllData(string name)
        {
            List<dynamic> allData = new List<dynamic>();
            List<dynamic> projectList = GetProjectList(name);
            foreach (dynamic item in projectList)
            {
                List<dynamic> stageList = GetProjectStageList(item.Id);
                allData.Add(new
                {
                    Id = item.Id,
                    PName = item.ProjectName,
                    CompanyName=item.CompanyName,
                    StageList = stageList
                }.ToDynamic());
            }
            return allData;
        }



        public static List<dynamic> GetProjectStageInfo(int projectStageId)
        {
            return ExecuteQuery.GetList(
                new QueryBase.QueryInfo()
                {
                    ProcName = "usp_GetProjectStageInfo",
                    Params = { projectStageId }
                });
        }

    }
}
